﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using MuseLibrary.EncodingHelpers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MuseLibraryTests
{
    [TestClass]
    public class QuotientParserFixture
    {
        [TestMethod]
        public void CanParseQuotient()
        {
            var quotientParser = new QuotientParser();
            var bitStream = "111100001".ToBools();
            var counter = 0;
            while (!quotientParser.ReadBit(bitStream[counter]))
            {
                counter++;
            }

            Assert.AreEqual(4, quotientParser.Quotient);

            quotientParser.ResetState();
            Assert.AreEqual(0, quotientParser.Quotient);
            bitStream = "111100001".ToBools();
            counter = 0;
            while (!quotientParser.ReadBit(bitStream[counter]))
            {
                counter++;
            }

            Assert.AreEqual(4, quotientParser.Quotient);

            quotientParser.ResetState();
            Assert.AreEqual(0, quotientParser.Quotient);
            bitStream = "1111111111111110000101100001010".ToBools();
            counter = 0;
            while (!quotientParser.ReadBit(bitStream[counter]))
            {
                counter++;
            }

            Assert.AreEqual(22, quotientParser.Quotient);

            quotientParser.ResetState();
            Assert.AreEqual(0, quotientParser.Quotient);
            bitStream = "0".ToBools();
            counter = 0;
            while (!quotientParser.ReadBit(bitStream[counter]))
            {
                counter++;
            }

            Assert.AreEqual(0, quotientParser.Quotient);
        }
    }
}
